/**   
* @Title: YwShenQingZxController.java 
* @Package com.zjdiepu.www.manage.api.zpp.controller 
* 
* @author zhangpp
* @date 2017年5月26日 下午4:40:06 
* @version V1.0   
*/
package com.zjdiepu.www.manage.api.zpp.controller;
import io.swagger.annotations.Api;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.zjdiepu.www.base.BaseController;
import com.zjdiepu.www.base.core.AbstractSysUser;
import com.zjdiepu.www.base.core.ApiResponse;
import com.zjdiepu.www.base.core.BaseException;
import com.zjdiepu.www.base.core.PageVo;
import com.zjdiepu.www.base.enums.type.AttachmentSort;
import com.zjdiepu.www.base.enums.type.DataDicType;
import com.zjdiepu.www.base.enums.type.OperateType;
import com.zjdiepu.www.base.enums.type.ResultFlagType;
import com.zjdiepu.www.common.util.CollectionInitUtil;
import com.zjdiepu.www.common.util.ZhppDateUtil;
import com.zjdiepu.www.commpent.RedisObjectClient;
import com.zjdiepu.www.dao.zpp.PublicDao;
import com.zjdiepu.www.dao.zx.ZxCreditQueryMapper;
import com.zjdiepu.www.ibiz.base.IDpBaseDataDictionaryService;
import com.zjdiepu.www.ibiz.base.IOtherAttachmentsService;
import com.zjdiepu.www.ibiz.base.ISysUserService;
import com.zjdiepu.www.ibiz.cache.ICachedDictionaryService;
import com.zjdiepu.www.ibiz.dz.IDzMortgageSubService;
import com.zjdiepu.www.ibiz.file.IQiniuFileService;
import com.zjdiepu.www.ibiz.system.IBaseSysParamsService;
import com.zjdiepu.www.ibiz.yw.IYwBusinessService;
import com.zjdiepu.www.ibiz.zpp.DaiZhongYwService;
import com.zjdiepu.www.ibiz.zpp.PublicService;
import com.zjdiepu.www.ibiz.zpp.YwShenQingZxService;
import com.zjdiepu.www.ibiz.zx.IZxCreditQueryService;
import com.zjdiepu.www.model.base.dto.DpBaseDataDictionary;
import com.zjdiepu.www.model.base.dto.OtherAttachments;
import com.zjdiepu.www.model.base.dto.SimpleDataDictionary;
import com.zjdiepu.www.model.base.dto.SysUser;
import com.zjdiepu.www.model.base.ext.DpBaseDataDictionaryExt;
import com.zjdiepu.www.model.system.dto.BaseSalersman;
import com.zjdiepu.www.model.system.dto.BaseSysParams;
import com.zjdiepu.www.model.yw.dto.YwBusiness;
import com.zjdiepu.www.model.zpp.dzyw.vo.BusinessVo;
import com.zjdiepu.www.model.zpp.fksh.ext.ParamsExt;
import com.zjdiepu.www.model.zpp.fksh.vo.ParamsVo;
import com.zjdiepu.www.model.zpp.pub.ext.WhereSqlExt;
import com.zjdiepu.www.model.zpp.pub.ext.ZxDataResult;
import com.zjdiepu.www.model.zpp.ywsl.ext.DataDictionaryExt;
import com.zjdiepu.www.model.zpp.ywsl.ext.DiepuQueryAutoListExt;
import com.zjdiepu.www.model.zpp.ywsl.ext.QueryFkExt;
import com.zjdiepu.www.model.zpp.ywsl.ext.QuerycredExt;
import com.zjdiepu.www.model.zpp.ywsl.ext.Zx_credit_queryExt;
import com.zjdiepu.www.model.zpp.ywsl.vo.QueryFkVo;
import com.zjdiepu.www.model.zpp.ywsl.vo.Zx_credit_queryVo;
import com.zjdiepu.www.model.zx.dto.ZxCreditQuery;


/**      
 * 项目名称：diepu-parent-manage   
 * 类名称：YwShenQingZxController   
 * 类描述：   
 * 创建人：zhangpp
 * 创建时间：2017年5月26日 下午4:40:06   
 * 修改人：zhangpp
 * 修改时间：2017年5月26日 下午4:40:06   
 * 修改备注：   
 * @version V1.0     
 */
@RestController
@RequestMapping(value= "YwShenQingZxController", produces="application/json;charset=UTF-8")
@Api(tags = {"作者：张鹏鹏，电话：15158822934"}, produces="application/json;charset=UTF-8")
public class YwShenQingZxController extends BaseController
{
	@Resource
	private PublicDao publicDao;
	
	@Resource
	private PublicService publicService;
	
	@Resource
	private YwShenQingZxService ywShenQingZxService;
	
	@Resource
	private ICachedDictionaryService iCachedDictionaryService; 
	
	@Resource
	private IDzMortgageSubService iDzMortgageSubService;
	
	@Resource
    private ICachedDictionaryService cachedDictionaryService;
	
	@Resource
	private IOtherAttachmentsService iOtherAttachmentsService;
	
	@Resource
	private IQiniuFileService iQiniuFileService;
	
	@Resource
	private IBaseSysParamsService iBaseSysParamsService;
	
	@Resource
	private IZxCreditQueryService iZxCreditQueryService;
	
	@Resource
	private IYwBusinessService iYwBusinessService;
	
	@Resource
	private ISysUserService iSysUserService;
	
	@Resource
	private IDpBaseDataDictionaryService iDpBaseDataDictionaryService;
	
	@Resource
	private DaiZhongYwService daiZhongYwService;
	
	@Resource
	private RedisObjectClient redisObjectClient;
	
	@Resource
	private ZxCreditQueryMapper zxCreditQueryMapper;
	
	
	//*********************************************杭州工行借口程序*********************************************
	
	//杭州工行借口入口查询
	@RequestMapping(value="diepuQueryAutoList",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> diepuQueryAutoList(DiepuQueryAutoListExt diepuQueryAutoListExt) throws Exception
	{
		Map<String, Object> maps = success();
		AbstractSysUser currentUser = getCurrentUser();
		
		//用户名称
		String userId = currentUser.getId();
		
		if(StringUtils.isBlank(userId))
		{
			throw new BaseException(ResultFlagType.LOGIN_TIMEOUT.getCode().toString(),ResultFlagType.LOGIN_TIMEOUT.getValue());
		}
		
		if(null == diepuQueryAutoListExt)
		{
			throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),ResultFlagType.PARAM_EMPTY.getValue());
		}
		
		//查询模块页面参数
		String modeIdName = diepuQueryAutoListExt.getModeIdName();
		if(StringUtils.isBlank(modeIdName))
		{
			throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),ResultFlagType.PARAM_EMPTY.getValue());
		}
		
		String whereSql = "";
		
		//条件查询
//		if(StringUtils.isNotBlank(diepuQueryAutoListExt.getSubmitTimeStart()) && StringUtils.isNotBlank(diepuQueryAutoListExt.getSubmitTimeEnd()))
		if(StringUtils.isNoneBlank(diepuQueryAutoListExt.getSubmitTimeStart(), diepuQueryAutoListExt.getSubmitTimeEnd()))
		{
			int submitTimeStart = ZhppDateUtil.dateConvertTimeStamp(diepuQueryAutoListExt.getSubmitTimeStart(), ZhppDateUtil.SHORT_DATE_FORMAT);
			int submitTimeEnd = ZhppDateUtil.dateConvertTimeStamp(diepuQueryAutoListExt.getSubmitTimeEnd(), ZhppDateUtil.SHORT_DATE_FORMAT);
			whereSql += " and t.created >= "+submitTimeStart;
			whereSql += " and t.created <= "+submitTimeEnd;
		}
		else if(StringUtils.isNotBlank(diepuQueryAutoListExt.getSubmitTimeStart()))
		{
			int submitTimeStart = ZhppDateUtil.dateConvertTimeStamp(diepuQueryAutoListExt.getSubmitTimeStart(), ZhppDateUtil.SHORT_DATE_FORMAT);
			whereSql += " and t.created >= "+submitTimeStart;
		}
		else if(StringUtils.isNotBlank(diepuQueryAutoListExt.getSubmitTimeEnd()))
		{
			int submitTimeEnd = ZhppDateUtil.dateConvertTimeStamp(diepuQueryAutoListExt.getSubmitTimeEnd(), ZhppDateUtil.SHORT_DATE_FORMAT);
			whereSql += " and t.created <= "+submitTimeEnd;
		}
		
		//业务受理 >业务申请 >增加配偶或担保人
		if(modeIdName.equals("autoCreditApplyAddList"))
		{
			
			maps = autoCreditApplyAddList(whereSql,diepuQueryAutoListExt.getOrderSql(),userId,diepuQueryAutoListExt.getCustomerName(),diepuQueryAutoListExt.getSalesmanName());
		}
		//业务受理  >业务申请 >征信修改列表
		else if(modeIdName.equals("autozxQueryCreditChangeList"))
		{
			maps = autozxQueryCreditChangeList(whereSql,diepuQueryAutoListExt.getOrderSql(),userId,diepuQueryAutoListExt.getCustomerName(),diepuQueryAutoListExt.getSalesmanName());
		}
		//业务受理>接口征信查询>修改订单业务员
		else if(modeIdName.equals("addYwYuanList"))
		{
			maps = addYwYuanList(whereSql,diepuQueryAutoListExt.getOrderSql(),userId,diepuQueryAutoListExt.getCustomerName(),diepuQueryAutoListExt.getSalesmanName());
		}
		return maps;
	}
	
	//业务受理>接口征信查询>修改订单业务员
	private Map<String, Object> addYwYuanList(String whereSql,String orderSql,String userId,String customerName,String salesmanName) throws Exception
	{
		Map<String, Object> maps = success();
		whereSql += " and t.busi_status < 30 ";
		String sqlXmls = " select t.code_unit from base_account_busi_unit t where 1 = 1 and t.dp_status = 1 and t.user_id = '"+userId+"' ";
		List<Map<String, String>> mapList = publicService.queryWhereSql(sqlXmls);
		if(null == mapList || 0 == mapList.size())
		{
			return maps;
		}
		if(mapList.size() > 0)
		{
			whereSql += " and ( ";
			
			Map<String, String> m = mapList.get(0);
			String code_unit = m.get("code_unit").toString();
			whereSql += " u.salersman_code like CONCAT('"+code_unit+"','%') ";
			
			for(int i=1;i<mapList.size();i++)
			{
				m = mapList.get(i);
				code_unit = m.get("code_unit").toString();
				whereSql += " or u.salersman_code like CONCAT('"+code_unit+"','%') ";
			}
			whereSql += " ) ";
		}
		
		//杭州工程改造
		whereSql += " and t.type_data = 3 ";
		whereSql += " and t.bank_loan = 'ICBC' ";
				
		com.zjdiepu.www.model.zpp.pub.ext.ParamsExt paramsExt = new com.zjdiepu.www.model.zpp.pub.ext.ParamsExt();
		paramsExt.setWhereSql(whereSql);
		paramsExt.setCustomerName(customerName);
		paramsExt.setSalesmanName(salesmanName);
		paramsExt.notDeleted();
        PageVo page = getPage(paramsExt);
        int records = daiZhongYwService.countYwYuanList(paramsExt);
        page.setRecords(records);
        if (records > 0) 
        {
        	paramsExt.setOrderSql(" t.created desc ");
        	List<BusinessVo> dhywDyVos = daiZhongYwService.getYwYuanList(paramsExt);
        	redisObjectClient.execute(new RedisCallback<Boolean>() {

				@Override
				public Boolean doInRedis(RedisConnection redisConnection)
						throws DataAccessException {
					for(int i=0;i<dhywDyVos.size();i++)
					{
						BusinessVo businessVo = dhywDyVos.get(i);
						String channelType = businessVo.getChannelType();
		            	SimpleDataDictionary simpleDataDictionary1 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), channelType, DataDicType.CHANNEL_TYPE.getCode());
		            	businessVo.setChannelType(simpleDataDictionary1 == null ? "" : simpleDataDictionary1.getName());
		            	
		            	String channelStatus = businessVo.getChannelStatus();
		            	SimpleDataDictionary simpleDataDictionary2 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), channelStatus, DataDicType.CHANNEL_STATUS.getCode());
		            	businessVo.setChannelStatus(simpleDataDictionary2 == null ? "" : simpleDataDictionary2.getName());
		            	
		            	String bankLoan = businessVo.getBankLoan();
		            	SimpleDataDictionary simpleDataDictionary3 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), bankLoan, DataDicType.LOAN_BANK.getCode());
		            	businessVo.setBankLoan(simpleDataDictionary3 == null ? "" : simpleDataDictionary3.getName());
					}
					return true;
				}
			});
            page.setRows(dhywDyVos);
            maps.put("result", page);
        } 
		return maps;
	}
	
	//业务受理  >业务申请 >征信修改列表
	private Map<String, Object> autozxQueryCreditChangeList(String whereSql,String orderSql,String userId,String customerName,String salesmanName) throws Exception
	{
		Map<String, Object> maps = success();
		whereSql += " and h.credit_query_status = 20 ";
		String sqlXmls = " select t.code_unit from base_account_busi_unit t where 1 = 1 and t.dp_status = 1 and t.user_id = '"+userId+"' ";
		List<Map<String, String>> mapList = publicService.queryWhereSql(sqlXmls);
		if(null == mapList || 0 == mapList.size())
		{
			return maps;
		}
		if(mapList.size() > 0)
		{
			whereSql += " and ( ";
			
			Map<String, String> m = mapList.get(0);
			String code_unit = m.get("code_unit").toString();
			whereSql += " saler.salersman_code like CONCAT('"+code_unit+"','%') ";
			
			for(int i=1;i<mapList.size();i++)
			{
				m = mapList.get(i);
				code_unit = m.get("code_unit").toString();
				whereSql += " or saler.salersman_code like CONCAT('"+code_unit+"','%') ";
			}
			whereSql += " ) ";
		}
		//杭州工程改造
		whereSql += " and v.type_data = 3 ";
		whereSql += " and t.bank_code = 'ICBC' ";
		
		QueryFkExt zxQueryFkExt = new QueryFkExt();
		zxQueryFkExt.setCus_name(customerName);
		zxQueryFkExt.setCreator_name(salesmanName);
		zxQueryFkExt.notDeleted();
        PageVo page = getPage(zxQueryFkExt);
        int records = ywShenQingZxService.countDanBaoRenByExt(zxQueryFkExt);
        page.setRecords(records);
        if (records > 0) 
        {
        	zxQueryFkExt.setOrderSql(" t.created desc ");
            List<QueryFkVo> dhywDyVos = ywShenQingZxService.getDanBaoRenList(zxQueryFkExt);
            
            for(int i=0;i<dhywDyVos.size();i++)
            {
             	QueryFkVo fk = dhywDyVos.get(i);
             	fk.setReasonBack(publicService.getDictionaryName(fk.getReasonBack(),DataDicType.CREDIT_RETURNED_REASON.getCode()));
             	fk.setBankCode(publicService.getDictionaryName(fk.getBankCode(), DataDicType.LOAN_BANK.getCode()));
            }
            page.setRows(dhywDyVos);
            maps.put("result", page);
        }
		return maps;
	}
	
	//业务受理 >业务申请 >增加配偶或担保人
	private Map<String, Object> autoCreditApplyAddList(String whereSql,String orderSql,String userId,String customerName,String salesmanName) throws Exception
	{
		Map<String, Object> maps = success();
		//不管是谁创建的菜单    都可以添加担保人或者配偶
		whereSql += " and t.credit_people_type = 03";
		String sqlXmls = " select t.code_unit from base_account_busi_unit t where 1 = 1 and t.dp_status = 1 and t.user_id = '"+userId+"' ";
		List<Map<String, String>> mapList = publicService.queryWhereSql(sqlXmls);
		if(null == mapList || 0 == mapList.size())
		{
			return maps;
		}
		if(mapList.size() > 0)
		{
			whereSql += " and ( ";
			Map<String, String> m = mapList.get(0);
			String code_unit = m.get("code_unit").toString();
			whereSql += " saler.salersman_code like CONCAT('"+code_unit+"','%') ";
			for(int i=1;i<mapList.size();i++)
			{
				m = mapList.get(i);
				code_unit = m.get("code_unit").toString();
				whereSql += " or saler.salersman_code like CONCAT('"+code_unit+"','%') ";
			}
			whereSql += " ) ";
		}
		//杭州工行改造
		whereSql += " and v.type_data = 3 ";
		whereSql += " and t.bank_code = 'ICBC' ";
		
		QueryFkExt zxQueryFkExt = new QueryFkExt();
		zxQueryFkExt.setCus_name(customerName);
		zxQueryFkExt.setCreator_name(salesmanName);
		zxQueryFkExt.setWhereSql(whereSql);
		zxQueryFkExt.notDeleted();
        PageVo page = getPage(zxQueryFkExt);
        int records = ywShenQingZxService.countDanBaoRenByExt(zxQueryFkExt);
        page.setRecords(records);
        if (records > 0) 
        {
        	if(StringUtils.isBlank(orderSql))
        	{
        		orderSql = "t.created desc ";
        	}
        	zxQueryFkExt.setOrderSql(orderSql);
            List<QueryFkVo> dhywDyVos = ywShenQingZxService.getDanBaoRenList(zxQueryFkExt);
            
            for(int i=0;i<dhywDyVos.size();i++)
            {
             	QueryFkVo fk = dhywDyVos.get(i);
             	fk.setReasonBack(publicService.getDictionaryName(fk.getReasonBack(),DataDicType.CREDIT_RETURNED_REASON.getCode()));
             	fk.setBankCode(publicService.getDictionaryName(fk.getBankCode(), DataDicType.LOAN_BANK.getCode()));
            }
            page.setRows(dhywDyVos);
            maps.put("result", page);
        }
		return maps;
	}
	
	
	
	//征信申请接收接口
	@RequestMapping(value="diepuAutoZxApply",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public ApiResponse diepuAutoZxApply(@ModelAttribute QuerycredExt zxQuerycredExt)throws Exception
	{
		AbstractSysUser currentUser = getCurrentUser();
		ywShenQingZxService.diepuAutoZxApply(currentUser,zxQuerycredExt);
		//开始生成征信文档
		ywShenQingZxService.diepuCreatedWord(currentUser,zxQuerycredExt);
		return ApiResponse.success(true);
	}
	
	//征信查询>接口查询>征信信息修改 撤销
	@RequestMapping(value="autoTranslateCredit",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> autoTranslateCredit(String zxCreditQueryId)
	{
		Map<String, Object> maps = success();
		ZxCreditQuery zxCreditQuery = zxCreditQueryMapper.selectByPrimaryKey(zxCreditQueryId);
		if(null == zxCreditQuery)
		{
			throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),"zxCreditQueryMapper selectByPrimaryKey is null");
		}
		AbstractSysUser currentUser = getCurrentUser();
		zxCreditQuery.initUpdateData(currentUser.getId(), currentUser.getName());
		zxCreditQuery.setCreditQueryStatus(999);
		int count = zxCreditQueryMapper.updateByPrimaryKeySelective(zxCreditQuery);
		if(count < 1)
		{
			throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),"zxCreditQueryMapper updateByPrimaryKeySelective error");
		}
		return maps;
	}
	
	//*********************************************杭州工行借口程序*********************************************
	
	//征信查询>人工查询>征信信息修改 撤销
	@RequestMapping(value="translateCredit",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> translateCredit(String zxCreditQueryId)
	{
		Map<String, Object> maps = success();
		ZxCreditQuery zxCreditQuery = zxCreditQueryMapper.selectByPrimaryKey(zxCreditQueryId);
		if(null == zxCreditQuery)
		{
			throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),"zxCreditQueryMapper selectByPrimaryKey is null");
		}
		AbstractSysUser currentUser = getCurrentUser();
		zxCreditQuery.initUpdateData(currentUser.getId(), currentUser.getName());
		zxCreditQuery.setCreditQueryStatus(999);
		int count = zxCreditQueryMapper.updateByPrimaryKeySelective(zxCreditQuery);
		if(count < 1)
		{
			throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),"zxCreditQueryMapper updateByPrimaryKeySelective error");
		}
		return maps;
	}
	
	/**
	*  查询业务信息表数据
	*  @author  zhangpp
	*  @Title:  getBusiness  
	*    
	*  @param  @param queryCreditApplyId
	*  @param  @return        设定文件  
	*  @return  Map<String,Object>        返回类型  
	*  @version  V1.0
	*  @throws
	 */
	@RequestMapping(value="getBusiness",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> getBusiness(String queryCreditApplyId)
	{
		Map<String, Object> maps = success();
		YwBusiness ywBusiness = new YwBusiness();
		ywBusiness.setQueryCreditApplyId(queryCreditApplyId);
		ywBusiness.setDpStatus(1);
		ywBusiness = iYwBusinessService.selectRefined(ywBusiness);
		maps.put("result", ywBusiness);;
		return maps;
	}
	
	/**
	*  慎选业务员
	*  @author  zhangpp
	*  @Title:  getBaseSalersman  
	*    
	*  @param  @return        设定文件  
	*  @return  Map<String,Object>        返回类型  
	*  @version  V1.0
	*  @throws
	 */
	@RequestMapping(value="getBaseSalersman",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> getBaseSalersman(String name)
	{
		Map<String, Object> maps = success();
		AbstractSysUser currentUser = getCurrentUser();
		String userId = currentUser.getId();
		String sqlXmls = " select t.code_unit from base_account_busi_unit t where 1 = 1 and t.dp_status = 1 and t.user_id = '"+userId+"' ";
		List<Map<String, String>> mapList = publicService.queryWhereSql(sqlXmls);
		if(null == mapList || 0 == mapList.size())
		{
			return maps;
		}
		sqlXmls = " and ( ";
		if(mapList.size() > 0)
		{
			Map<String, String> m = mapList.get(0);
			String code_unit = m.get("code_unit").toString();
			sqlXmls += " t.salersman_code like CONCAT('"+code_unit+"','%') ";
			
			for(int i=1;i<mapList.size();i++)
			{
				m = mapList.get(i);
				code_unit = m.get("code_unit").toString();
				sqlXmls += " or t.salersman_code like CONCAT('"+code_unit+"','%') ";
			}
		}
		sqlXmls += " ) ";
		
		if(null != name && !("").equals(name))
		{
			sqlXmls += " and t.name like concat('%','"+name+"', '%')";
		}
		else
		{
			sqlXmls += " limit 10";
		}
		
		List<BaseSalersman> result = ywShenQingZxService.getBaseSalersman(sqlXmls);
		maps.put("result", result);
		return maps;
	}

	/**
	* 征信自动导出数据
	* @author zhangpp
	* @Title: extZhengxin 
	* 
	* @param @param replaceId
	* @param @param credit_result_mark
	* @param @return    设定文件 
	* @return Map<String,Object>    返回类型 
	* @version V1.0
	* @throws
	 */
	@RequestMapping(value="extZhengxin",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> extZhengxin(int pass)
	{
		AbstractSysUser currentUser = getCurrentUser();
		Map<String, Object> maps = success();
		ywShenQingZxService.diepuExtZhengxin(pass,currentUser);
		return maps;
	}
	
	
	/**
	* 征信结果执行修改
	* @author zhangpp
	* @Title: updateZhengXinFanKuiResult 
	* 
	* @param @param replaceId
	* @param @return    设定文件 
	* @return Map<String,Object>    返回类型 
	* @version V1.0
	* @throws
	 */
	@RequestMapping(value="updateZhengXinFanKuiResult",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> updateZhengXinFanKuiResult(String replaceId,String credit_result_mark)
	{
		Map<String, Object> maps = success();
		
		//查询征信结果数据
		ZxCreditQuery zxCreditQuery = new ZxCreditQuery();
		zxCreditQuery.setQueryCreditApplySubId(replaceId);
		zxCreditQuery.setDpStatus(1);
		zxCreditQuery = iZxCreditQueryService.selectRefined(zxCreditQuery);
		if(null != zxCreditQuery && !("").equals(zxCreditQuery))
		{
			//征信主表主键
			String query_credit_apply_id = zxCreditQuery.getQueryCreditApplyId();
			
			//查询业务信息表数据
			YwBusiness ywBusiness = new YwBusiness();
			ywBusiness.setQueryCreditApplyId(query_credit_apply_id);
			ywBusiness.setDpStatus(1);
			ywBusiness = iYwBusinessService.selectRefined(ywBusiness);
			
			if(null != ywBusiness && !("").equals(ywBusiness))
			{
				if(ywBusiness.getBusiStatus() >= 30)
				{
					return super.errorMassage("当前数据已经在审核当中，无法进行修改！", 100400);
				}
				
				ZxCreditQuery creditQuery = new ZxCreditQuery();
				creditQuery.setId(zxCreditQuery.getId());
				creditQuery.setCreditResultMark(credit_result_mark);
				iZxCreditQueryService.saveUpdateAndDelete(creditQuery, OperateType.edit);
			}
		}
        return maps;
	}
	
	
	/**
	* 查询征信数据结果
	* @author zhangpp
	* @Title: getZhengXinFanKuiResult 
	* 
	* @param @param zxcxApplyId
	* @param @return    设定文件 
	* @return Map<String,Object>    返回类型 
	* @version V1.0
	* @throws
	 */
	@RequestMapping(value="getZhengXinFanKuiResult",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> getZhengXinFanKuiResult(String replaceId)
	{
		Map<String, Object> maps = success();
		String sqlXmls = "select t.id,t.credit_result,t.once_car_status,t.credit_result_mark,t.remarks from zx_credit_query t where t.query_credit_apply_sub_id = '"+replaceId+"' and t.dp_status = 1";
		List<Map<String, String>> list = publicDao.queryWhereSql(sqlXmls);
		maps.put("result", list);
        return maps;
	}
	
	
	/**
	* 下载征信文档
	* @author zhangpp
	* @Title: saveWordToQiniu 
	* 
	* @param @param zxQueryFkExt
	* @param @return    设定文件 
	* @return Map<String,Object>    返回类型 
	* @version V1.0
	* @throws
	 */
	@RequestMapping(value="saveWordToQiniu",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> saveWordToQiniu(String zxcxApplyId,String credit_People_Type,String zxsubId)
	{
		Map<String, Object> maps = success();
		String sqlXmls = "";
		
		//主借人
		if(credit_People_Type.equals("SHEN_FEN_ZHENG_MING_01"))
		{
			sqlXmls = "select count(t.id) count from other_attachments t where t.dataid = '"+zxcxApplyId+"' and t.sub_dataid = '"+zxcxApplyId+"' and t.attachment_type = 'word' and t.dp_status = 1";
		}
		else
		{
			sqlXmls = "select count(t.id) count from other_attachments t where t.dataid = '"+zxcxApplyId+"' and t.sub_dataid = '"+zxsubId+"' and t.attachment_type = 'word' and t.dp_status = 1";
		}
		int count = publicDao.countSqlXmls(sqlXmls);
		if(count < 1)
		{
			return maps;
		}
		
		
		//删除文档信息
		WhereSqlExt whereSqlExt = new WhereSqlExt();
		String whereSql = "delete from other_attachments where dataid = '"+zxcxApplyId+"' and attachment_type = 'word' and mode_id = 'M_zxcx' and dp_status = 1";
		whereSqlExt.setWhereSql(whereSql);
		publicDao.deleteWhereSql(whereSqlExt);
		
		AbstractSysUser currentUser = getCurrentUser();
		
		String wordOsspth = ""; 
		
		if(credit_People_Type.equals("SHEN_FEN_ZHENG_MING_01"))
		{
			wordOsspth = iOtherAttachmentsService.saveWordToQiniu(zxcxApplyId,zxsubId,AttachmentSort.SHEN_FEN_ZHENG_MING, currentUser);
		}
		else if(credit_People_Type.equals("PEI_OU_SHEN_FEN_ZHENG_MING_01"))
		{
			wordOsspth = iOtherAttachmentsService.saveWordToQiniu(zxcxApplyId,zxsubId, AttachmentSort.PEI_OU_SHEN_FEN_ZHENG_MING, currentUser);
		}
		else if(credit_People_Type.equals("DAN_BAO_REN_SHEN_FEN_ZHENG_MING_1_01"))
		{
			wordOsspth = iOtherAttachmentsService.saveWordToQiniu(zxcxApplyId, zxsubId,AttachmentSort.DAN_BAO_REN_SHEN_FEN_ZHENG_MING_1, currentUser);
		}
		else if(credit_People_Type.equals("DAN_BAO_REN_SHEN_FEN_ZHENG_MING_1_02"))
		{
			wordOsspth = iOtherAttachmentsService.saveWordToQiniu(zxcxApplyId,zxsubId, AttachmentSort.DAN_BAO_REN_SHEN_FEN_ZHENG_MING_2, currentUser);
		}
		else if(credit_People_Type.equals("DAN_BAO_REN_SHEN_FEN_ZHENG_MING_1_03"))
		{
			wordOsspth = iOtherAttachmentsService.saveWordToQiniu(zxcxApplyId,zxsubId, AttachmentSort.DAN_BAO_REN_SHEN_FEN_ZHENG_MING_3, currentUser);
		}
		else 
		{
			wordOsspth = iOtherAttachmentsService.saveWordToQiniu(zxcxApplyId, zxsubId,AttachmentSort.DAN_BAO_REN_SHEN_FEN_ZHENG_MING_4, currentUser);
		}
		maps.put("wordOsspth", wordOsspth);
        return maps;
	}
	
	/**
	* 获取下载地址
	* @author zhangpp
	* @Title: getQiuUrl 
	* 
	* @param @param zxcxApplyId
	* @param @return    设定文件 
	* @return Map<String,Object>    返回类型 
	* @version V1.0
	* @throws
	 */
	@RequestMapping(value="getQiuUrl",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> getQiuUrl(String zxcxApplyId,String subDataid)
	{
		Map<String, Object> maps = success();
		OtherAttachments otherAttachments = new OtherAttachments();
		otherAttachments.setDataid(zxcxApplyId);
		otherAttachments.setModeId("M_zxcx");
		otherAttachments.setSubDataid(subDataid);
		otherAttachments.setAttachmentType("word");
		otherAttachments.setDpStatus(1);
		otherAttachments = iOtherAttachmentsService.selectRefined(otherAttachments);
		String bigUrl = "";
		if(null != otherAttachments && !("").equals(otherAttachments))
		{
			bigUrl = iQiniuFileService.getURL(otherAttachments.getOssPath());
		}
		maps.put("bigUrl", bigUrl);
        return maps;
	}
	
	/**
	* 征信查询&反馈单条数据
	* @author zhangpp
	* @Title: getEntityService 
	* 
	* @param @param dhywDyExt
	* @param @return    设定文件 
	* @return Map<String,Object>    返回类型 
	* @version V1.0
	* @throws
	 */
	@RequestMapping(value="getEntityService",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> getEntityService(@ModelAttribute QueryFkExt zxQueryFkExt)
	{
		Map<String, Object> maps = success();
		QueryFkVo zxQueryFkVo = ywShenQingZxService.getEntity(zxQueryFkExt);
		zxQueryFkVo.setBankCode(publicService.getDictionaryName(zxQueryFkVo.getBankCode(), DataDicType.LOAN_BANK.getCode()));
		DataDictionaryExt dataDictionaryExt = new DataDictionaryExt();
    	dataDictionaryExt.setPname(DataDicType.CREDIT_RETURNED_REASON.getValue());
    	maps.put("zxQueryFkVo", zxQueryFkVo);
    	
    	Map<String, String> creditReturnedReason_Result = iCachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CREDIT_RETURNED_REASON,"请选择...");
    	maps.put("creditReturnedReason_Result", creditReturnedReason_Result);
		
		//系统参数表取值
		BaseSysParams baseSysParams = new BaseSysParams();
		baseSysParams.setCodeParam("CreditExpiryDate");
		baseSysParams.setDpStatus(1);
		baseSysParams = iBaseSysParamsService.selectRefined(baseSysParams);
		String enddate = "";
		if(null != baseSysParams && !("").equals(baseSysParams))
		{
			Date date = new Date();
			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
			Calendar ca = Calendar.getInstance();
			ca.add(Calendar.DATE, Integer.valueOf(baseSysParams.getValueParam()));
			date = ca.getTime();
			enddate = format.format(date);
		}
		maps.put("enddate", enddate);
		
        return maps;
	}
	
	
	/**
	*字典表查询 
	* @author zhangpp
	* @Title: getDataDictionaryList 
	* 
	* @param @return    设定文件 
	* @return Map<String,Object>    返回类型 
	* @version V1.0
	* @throws
	 */
	@RequestMapping(value="getDataDictionaryList",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> getDataDictionaryList()
	{
		Map<String, Object> maps = success();
		
		//财务相关/结清单确认
		Map<String, String> caiwujieqing_result = iCachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAIWU_XIANGGUAN_BANK_TUIJIAN,"请选择...");
		maps.put("caiwujieqing_result", caiwujieqing_result);
		
		//结算方式
		Map<String, String> SettlementType_result = iCachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.SETTLEMENT_TYPE,"请选择...");
		maps.put("SettlementType_result", SettlementType_result);
		
		//退贷原因
		Map<String, String> LoanExitReason_Result = iCachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.LOANEXIT_REASON,"请选择...");
		maps.put("LoanExitReason_Result", LoanExitReason_Result);
		
		//贷款银行
		Map<String, String> LoanBank_result = iCachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.LOAN_BANK,"请选择...");
		maps.put("LoanBank_result", LoanBank_result);
		
        return maps;
	}
	
	/**
	* 业务受理 申请征信  征信开始分配
	* @author zhangpp
	* @Title: saveZhengXinData 
	* 
	* @param @param paramsExt
	* @param @return
	* @param @throws Exception    设定文件 
	* @return ApiResponse    返回类型 
	* @version V1.0
	* @throws
	 */
	@RequestMapping(value="saveZhengXinData",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public ApiResponse saveZhengXinData(@ModelAttribute ParamsExt paramsExt) throws Exception
	{
		AbstractSysUser currentUser = getCurrentUser();
		ywShenQingZxService.saveZhengXinData(paramsExt, currentUser);
        return ApiResponse.success(true);
	}
	
	/**
	* 业务受理 申请征信  查征信派单 
	* @author zhangpp
	* @Title: getCreditQueryList 
	* 
	* @param @param zx_credit_queryExt
	* @param @return
	* @param @throws Exception    设定文件 
	* @return ApiResponse    返回类型 
	* @version V1.0
	* @throws
	 */
	@RequestMapping(value="getCreditQueryList",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public ApiResponse getCreditQueryList(@ModelAttribute Zx_credit_queryExt zx_credit_queryExt) throws Exception
	{
		String whereSql = " and h.operator_id is null ";
		SysUser sysUser =(SysUser)getCurrentUser();
		String lBank = sysUser.getLoanBank();
		DpBaseDataDictionaryExt  dpBaseDataDictionaryExt = new DpBaseDataDictionaryExt();
		dpBaseDataDictionaryExt.setBaseWhere();
		dpBaseDataDictionaryExt.withOutPage();
		dpBaseDataDictionaryExt.setParentValue(DataDicType.LOAN_BANK.getCode());
		List<DpBaseDataDictionary> list = iDpBaseDataDictionaryService.selectByExt(dpBaseDataDictionaryExt);
		if(null != list && list.size() > 0)
		{
			List<String> tmpe = iSysUserService.listBankCodes(lBank);
			whereSql += " and v.bank_code in ( '@@@',";
			for(int i=0;i<list.size();i++)
			{
				DpBaseDataDictionary dp =  list.get(i);
				
				if(tmpe.contains(dp.getValue()))
				{
					whereSql += "'"+list.get(i).getValue()+"',";
				}
			}
			whereSql = whereSql.substring(0,whereSql.length()-1);
			whereSql += " ) ";
		}
		
		zx_credit_queryExt.setWhereSql(whereSql);
		String orderSql = " t.created desc ";
		zx_credit_queryExt.setOrderSql(orderSql);
		
		zx_credit_queryExt.notDeleted();
        PageVo page = getPage(zx_credit_queryExt);
        int records = ywShenQingZxService.getCreditQueryCount(zx_credit_queryExt);
        page.setRecords(records);
        if (records > 0) 
        {
            List<Zx_credit_queryVo> dhywDyVos = ywShenQingZxService.getCreditQueryList(zx_credit_queryExt);
            
            for(int i=0;i<dhywDyVos.size();i++)
            {
            	Zx_credit_queryVo z = 	dhywDyVos.get(i);
            	//z.setBankCode(cachedDictionaryService.getName(z.getBankCode(), DataDicType.LOAN_BANK));
            	z.setBankCode(publicService.getDictionaryName(z.getBankCode(), DataDicType.LOAN_BANK.getCode()));
            }
            
            page.setRows(dhywDyVos);
        } 
        else 
        {
            page.setRows(CollectionInitUtil.emptyList());
        }
        return ApiResponse.success(page);
	}
	
	/**
	*  获取银行
	*  @author  zhangpp
	*  @Title:  getLoanBank  
	*    
	*  @param  @return
	*  @param  @throws Exception        设定文件  
	*  @return  ApiResponse        返回类型  
	*  @version  V1.0
	*  @throws
	 */
	@RequestMapping(value="getLoanBank",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> getLoanBank() throws Exception
	{
		Map<String, Object> maps = success();
		SysUser sysUser =(SysUser)getCurrentUser();
		String lBank = sysUser.getLoanBank();
		Map<String, String> bankMaps = CollectionInitUtil.emptyMap();
		DpBaseDataDictionaryExt  dpBaseDataDictionaryExt = new DpBaseDataDictionaryExt();
		dpBaseDataDictionaryExt.setBaseWhere();
		dpBaseDataDictionaryExt.withOutPage();
		dpBaseDataDictionaryExt.setParentValue(DataDicType.LOAN_BANK.getCode());
		List<DpBaseDataDictionary> list = iDpBaseDataDictionaryService.selectByExt(dpBaseDataDictionaryExt);
		if(null != list && list.size() > 0)
		{
			List<String> tmpe = iSysUserService.listBankCodes(lBank);
			for(int i=0;i<list.size();i++)
			{
				DpBaseDataDictionary dp =  list.get(i);
				
				if(tmpe.contains(dp.getValue()))
				{
					bankMaps.put(list.get(i).getValue(),list.get(i).getName());
				}
				maps.put("bankMaps", bankMaps);
			}
		}
		return maps;
	}
	
	
	/**
	* 业务受理  业务申请  查征信派单
	* @author zhangpp
	* @Title: getOpList 
	* 
	* @param @param paramsExt
	* @param @return
	* @param @throws Exception    设定文件 
	* @return ApiResponse    返回类型 
	* @version V1.0
	* @throws
	 */
	@RequestMapping(value="getOpList",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public ApiResponse getOpList(@ModelAttribute ParamsExt paramsExt) throws Exception
	{
		List<ParamsVo> paramsVo = ywShenQingZxService.getOpList(paramsExt);
        return ApiResponse.success(paramsVo);
	}
	
	/**
	* 征信查询
	* @author zhangpp
	* @Title: zxSave 
	* 
	* @param @return    设定文件 
	* @return Map<String,Object>    返回类型 
	* @version V1.0
	* @throws
	 */
	@RequestMapping(value="diepuZxApply",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public ApiResponse diepuZxApply(@ModelAttribute QuerycredExt zxQuerycredExt)throws Exception
	{
		//征信添加
		AbstractSysUser currentUser = getCurrentUser();
		ywShenQingZxService.diepuZxApply(zxQuerycredExt,currentUser, true);
		//开始生成征信文档
		ywShenQingZxService.diepuCreatedWord(currentUser,zxQuerycredExt);
		return ApiResponse.success(true);
	}
	
	/**
	 * @throws Exception 
	* 业务受理 申请征信 征信信息修改
	* @author zhangpp
	* @Title: zxUpdate 
	* 
	* @param @param zxQuerycredExt
	* @param @return    设定文件 
	* @return ApiResponse    返回类型 
	* @version V1.0
	* @throws
	 */
	@RequestMapping(value="zxUpdate",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public ApiResponse zxUpdate(@ModelAttribute QuerycredExt zxQuerycredExt) throws Exception
	{
		//征信修改
		AbstractSysUser currentUser = getCurrentUser();
		ywShenQingZxService.diepuZxUpdate(zxQuerycredExt,currentUser, false);
		
		//开始生成征信文档
    	ywShenQingZxService.diepuCreatedWord(currentUser,zxQuerycredExt);
		return ApiResponse.success(true);
	}
	
	
	//征信修改提交
	@RequestMapping(value="diepuAutoZxUpdate",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public ApiResponse diepuAutoZxUpdate(@ModelAttribute QuerycredExt zxQuerycredExt) throws Exception
	{
		//征信修改
		AbstractSysUser currentUser = getCurrentUser();
		ywShenQingZxService.diepuAutoZxUpdate(zxQuerycredExt,currentUser, false);
		
		//开始生成征信文档
    	ywShenQingZxService.diepuCreatedWord(currentUser,zxQuerycredExt);
		return ApiResponse.success(true);
	}
	
	/**
	* 业务受理 业务申请  征信信息修改
	* @author zhangpp
	* @Title: getSQServiceById 
	* 
	* @param @param zxQueryFkExt
	* @param @return    设定文件 
	* @return Map<String,Object>    返回类型 
	* @version V1.0
	* @throws
	 */
	@RequestMapping(value="getSQServiceById",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> getSQServiceById(@ModelAttribute QueryFkExt zxQueryFkExt)
	{
		Map<String, Object> maps = success();
		
		//征信字表的信息
		String whereSql = " and t.id = '"+zxQueryFkExt.getId()+"' limit 1";
		zxQueryFkExt.setWhereSql(whereSql);
		List<QueryFkVo> entity = ywShenQingZxService.getSQServiceById(zxQueryFkExt);
		if(null != entity && 0 != entity.size())
		{
			for(int i=0;i<entity.size();i++)
			{
				QueryFkVo q = entity.get(i);
				q.setReasonBack(publicService.getDictionaryName(q.getReasonBack(), DataDicType.CREDIT_RETURNED_REASON.getCode()));
			}
		}
		maps.put("result", entity);
		
		//征信主表的信息
		if(null != entity && 0 != entity.size())
		{
			whereSql = " and v.id = '"+entity.get(0).getReplaceId()+"' and t.credit_people_type = '03' limit 1";
			zxQueryFkExt.setWhereSql(whereSql);
			List<QueryFkVo> entityResult = ywShenQingZxService.getSQServiceById(zxQueryFkExt);
			maps.put("entityResult", entityResult);
		}
		
		//配偶增加的个数
		if(null != entity && 0 != entity.size())
		{
			whereSql = " and v.id = '"+entity.get(0).getReplaceId()+"' and t.credit_people_type = '01'";
			zxQueryFkExt.setWhereSql(whereSql);
			List<QueryFkVo> entityResult = ywShenQingZxService.getSQServiceById(zxQueryFkExt);
			maps.put("poCount", entityResult.size());
		}
		
		//银行的字典的数据
		Map<String, String> LoanBank_result = iCachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.LOAN_BANK,"请选择...");
		maps.put("LoanBank_result", LoanBank_result);
		
		//返回
        return maps;
	}
	
	/**
	* 业务受理 业务申请 征信查询反馈 
	* @author zhangpp
	* @Title: zxUpdateStatusTextService 
	* 
	* @param @return    设定文件 
	* @return Map<String,Object>    返回类型 
	* @version V1.0
	* @throws
	 */
	@RequestMapping(value="zxUpdateStatusTextService",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public ApiResponse zxUpdateStatusTextService(QueryFkExt zxQueryFkExt) throws Exception
	{
		AbstractSysUser currentUser = getCurrentUser();
		ywShenQingZxService.diepuZxUpdateStatusTextService(zxQueryFkExt,currentUser);
		return ApiResponse.success(true);
	}
	
	/**
	 * 征信反馈
	 * @return
	 */
	@RequestMapping(value="creditFeedback",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> creditFeedback(QueryFkExt zxQueryFkExt,String creditResultMark) throws Exception
	{
		Map<String, Object> maps = success();
		AbstractSysUser currentUser = getCurrentUser();
		if(null != zxQueryFkExt) {
			zxQueryFkExt.setCredit_result_mark(creditResultMark);
		}
		ywShenQingZxService.diepuZxUpdateStatusTextService(zxQueryFkExt,currentUser);
		return maps;
	}
	
	/**
	* 业务受理  申请征信  征信查询反馈 
	* @author zhangpp
	* @Title: getList 
	* 
	* @param @param zxQueryFkExt
	* @param @return
	* @param @throws Exception    设定文件 
	* @return ApiResponse    返回类型 
	* @version V1.0
	* @throws
	 */
	@RequestMapping(value="getList",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> getList(QueryFkExt zxQueryFkExt,ParamsExt paramsExt) throws Exception
	{
		Map<String, Object> maps = success();
		
		AbstractSysUser currentUser = getCurrentUser();
		
		String userId = currentUser.getId();
		
		String whereSql = "";
		
		//条件查询
		if(StringUtils.isNotBlank(paramsExt.getSubmitTimeStart()) && StringUtils.isNotBlank(paramsExt.getSubmitTimeEnd()))
		{
			int submitTimeStart = ZhppDateUtil.dateConvertTimeStamp(paramsExt.getSubmitTimeStart(), ZhppDateUtil.SHORT_DATE_FORMAT);
			int submitTimeEnd = ZhppDateUtil.dateConvertTimeStamp(paramsExt.getSubmitTimeEnd(), ZhppDateUtil.SHORT_DATE_FORMAT);
			whereSql += " and t.created >= "+submitTimeStart;
			whereSql += " and t.created <= "+submitTimeEnd;
		}
		else if(StringUtils.isNotBlank(paramsExt.getSubmitTimeStart()))
		{
			int submitTimeStart = ZhppDateUtil.dateConvertTimeStamp(paramsExt.getSubmitTimeStart(), ZhppDateUtil.SHORT_DATE_FORMAT);
			whereSql += " and t.created >= "+submitTimeStart;
		}
		else if(StringUtils.isNotBlank(paramsExt.getSubmitTimeEnd()))
		{
			int submitTimeEnd = ZhppDateUtil.dateConvertTimeStamp(paramsExt.getSubmitTimeEnd(), ZhppDateUtil.SHORT_DATE_FORMAT);
			whereSql += " and t.created <= "+submitTimeEnd;
		}
		
		if(null != paramsExt && !("").equals(paramsExt))
		{
			//业务受理 业务申请  征信查询反馈
			if(paramsExt.getExamineStatus().equals("M_zxcxfk"))
			{
				//主借人返回修改后 不影响其他的用户
				whereSql += "  and h.credit_query_status = 10 ";
				
				//杭州系统改造
				whereSql += " and v.type_data < 3  ";
				
				SysUser sysUser = new SysUser();
				sysUser.setId(currentUser.getId());
				sysUser.setDpStatus(1);
				sysUser = iSysUserService.selectRefined(sysUser);
				if(null != sysUser) {
					String lBank = sysUser.getLoanBank();
//					DpBaseDataDictionaryExt  dpBaseDataDictionaryExt = new DpBaseDataDictionaryExt();
//					dpBaseDataDictionaryExt.setBaseWhere();
//					dpBaseDataDictionaryExt.withOutPage();
//					dpBaseDataDictionaryExt.setParentValue(DataDicType.LOAN_BANK.getCode());
//					List<DpBaseDataDictionary> list = iDpBaseDataDictionaryService.selectByExt(dpBaseDataDictionaryExt);
//					
//					List<String> tmpe = iSysUserService.listBankCodes(lBank);
//					whereSql += " and t.bank_code in ( '@@@',";
//					for(int i=0;i<list.size();i++)
//					{
//						DpBaseDataDictionary dp =  list.get(i);
//						
//						if(tmpe.contains(dp.getValue()))
//						{
//							whereSql += "'"+list.get(i).getValue()+"',";
//						}
//					}
//					@update 2018-01-31  征信查询&反馈调整列表页面，增加贷款银行筛选
					List<String> bankCodes = iSysUserService.listBankCodes(lBank);
					if(CollectionUtils.isEmpty(bankCodes)) {
						whereSql += "AND 1=2";
					} else {
						whereSql += " AND t.bank_code in (";
						for(String loanBank : bankCodes){
							whereSql += "'"+loanBank+"',";
						}
					}
					whereSql = whereSql.substring(0,whereSql.length()-1);
					whereSql += ") ";
				}
			}
			
			//业务受理 业务申请 征信信息修改查询
			if(paramsExt.getExamineStatus().equals("M_zxxxxg"))
			{
				whereSql += " and h.credit_query_status = 20 ";
				String sqlXmls = " select t.code_unit from base_account_busi_unit t where 1 = 1 and t.dp_status = 1 and t.user_id = '"+userId+"' ";
				List<Map<String, String>> mapList = publicService.queryWhereSql(sqlXmls);
				if(null == mapList || 0 == mapList.size())
				{
					return maps;
				}
				if(mapList.size() > 0)
				{
					whereSql += " and ( ";
					
					Map<String, String> m = mapList.get(0);
					String code_unit = m.get("code_unit").toString();
					whereSql += " saler.salersman_code like CONCAT('"+code_unit+"','%') ";
					
					for(int i=1;i<mapList.size();i++)
					{
						m = mapList.get(i);
						code_unit = m.get("code_unit").toString();
						whereSql += " or saler.salersman_code like CONCAT('"+code_unit+"','%') ";
					}
					whereSql += " ) ";
				}
				
				//杭州工程改造
				whereSql += " and v.type_data < 3 ";
				
				zxQueryFkExt.setWhereSql(whereSql);
				zxQueryFkExt.notDeleted();
		        PageVo page = getPage(zxQueryFkExt);
		        int records = ywShenQingZxService.countDanBaoRenByExt(zxQueryFkExt);
		        page.setRecords(records);
		        if (records > 0) 
		        {
		        	zxQueryFkExt.setOrderSql(" t.created desc ");
		            List<QueryFkVo> dhywDyVos = ywShenQingZxService.getDanBaoRenList(zxQueryFkExt);
		            
		            for(int i=0;i<dhywDyVos.size();i++)
	                {
	                 	QueryFkVo fk = dhywDyVos.get(i);
	                 	fk.setReasonBack(publicService.getDictionaryName(fk.getReasonBack(),DataDicType.CREDIT_RETURNED_REASON.getCode()));
	                 	fk.setBankCode(publicService.getDictionaryName(fk.getBankCode(), DataDicType.LOAN_BANK.getCode()));
	                }
		            page.setRows(dhywDyVos);
		        }
		        maps.put("result", page);
	            return maps;
			}
			
			//业务受理  业务申请  增加配偶或担保人查询
			if(paramsExt.getExamineStatus().equals("M_zjdbrhpo"))
			{
				
				int submitTimeStart = ZhppDateUtil.dateConvertTimeStamp(ZhppDateUtil.DateToString(new Date(), "yyyy-MM"+"-01"), ZhppDateUtil.SHORT_DATE_FORMAT);
				whereSql += " and t.created >= "+submitTimeStart;
				
				
				//不管是谁创建的菜单    都可以添加担保人或者配偶
				whereSql += " and t.credit_people_type = 03";
				String sqlXmls = " select t.code_unit from base_account_busi_unit t where 1 = 1 and t.dp_status = 1 and t.user_id = '"+userId+"' ";
				List<Map<String, String>> mapList = publicService.queryWhereSql(sqlXmls);
				if(null == mapList || 0 == mapList.size())
				{
					return maps;
				}
				if(mapList.size() > 0)
				{
					whereSql += " and ( ";
					Map<String, String> m = mapList.get(0);
					String code_unit = m.get("code_unit").toString();
					whereSql += " saler.salersman_code like CONCAT('"+code_unit+"','%') ";
					for(int i=1;i<mapList.size();i++)
					{
						m = mapList.get(i);
						code_unit = m.get("code_unit").toString();
						whereSql += " or saler.salersman_code like CONCAT('"+code_unit+"','%') ";
					}
					whereSql += " ) ";
				}
				
				//杭州工行改造
				whereSql += " and v.type_data < 3 ";
				
				zxQueryFkExt.setWhereSql(whereSql);
				zxQueryFkExt.notDeleted();
		        PageVo page = getPage(zxQueryFkExt);
		        zxQueryFkExt.setRows(15);
		        int records = ywShenQingZxService.countDanBaoRenByExt(zxQueryFkExt);
		        page.setRecords(records);
		        if (records > 0) 
		        {
		        	if(StringUtils.isBlank(paramsExt.getOrderSql()))
		        	{
		        		paramsExt.setOrderSql(" t.created desc ");
		        	}
		        	zxQueryFkExt.setOrderSql(paramsExt.getOrderSql());
		        	zxQueryFkExt.setWhereSql(whereSql);
		            List<QueryFkVo> dhywDyVos = ywShenQingZxService.getDanBaoRenList(zxQueryFkExt);
		            
		            for(int i=0;i<dhywDyVos.size();i++)
	                {
	                 	QueryFkVo fk = dhywDyVos.get(i);
	                 	fk.setReasonBack(publicService.getDictionaryName(fk.getReasonBack(),DataDicType.CREDIT_RETURNED_REASON.getCode()));
	                 	fk.setBankCode(publicService.getDictionaryName(fk.getBankCode(), DataDicType.LOAN_BANK.getCode()));
	                }
		            page.setRows(dhywDyVos);
		        }
		        maps.put("result", page);
		        
		        //获取银行
		        Map<String, String> loanBank = iCachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.LOAN_BANK,"请选择...");
	            maps.put("loanBank", loanBank);
	            return maps;
			}
			
			String submitTimeStart = paramsExt.getSubmitTimeStart();
			String submitTimeEnd = paramsExt.getSubmitTimeEnd();
			
			if((null != submitTimeStart && !("").equals(submitTimeStart)) && null != submitTimeEnd && !("").equals(submitTimeEnd))
			{
				int begDate = ZhppDateUtil.dateConvertTimeStamp(submitTimeStart, "yyyy-MM-dd");
				int endDate = ZhppDateUtil.dateConvertTimeStamp(submitTimeEnd, "yyyy-MM-dd");
				
				whereSql += " and t.created >= "+begDate + " and t.created < "+(endDate + 86400);
			}
			else if(null != submitTimeEnd && !("").equals(submitTimeEnd))
			{
				int begDate = ZhppDateUtil.dateConvertTimeStamp(submitTimeStart, "yyyy-MM-dd");
				
				whereSql += " and t.created <= "+begDate;
			}
			else if(null != submitTimeStart && !("").equals(submitTimeStart))
			{
				int begDate = ZhppDateUtil.dateConvertTimeStamp(submitTimeStart, "yyyy-MM-dd");
				
				whereSql += " and t.created >= "+begDate;
			}
			
			//征信反馈
			String examinStatus = paramsExt.getExamineStatus();
			if(null != examinStatus && examinStatus.equals("M_zxfk"))
			{
				String cus_name = zxQueryFkExt.getCus_name();
				String customerName = zxQueryFkExt.getCreator_name();
				
				if((null == cus_name || ("").equals(cus_name)) && (null == customerName || ("").equals(customerName)))
				{
					maps.put("result", maps);
					return maps;
				}
				whereSql += " and h.credit_query_status = 40 and h.operator_id = '"+userId+"' ";
				
				//杭州系统改造
				whereSql += " and v.type_data < 3 ";
			}
		}
		
		zxQueryFkExt.setWhereSql(whereSql);
		zxQueryFkExt.notDeleted();
        PageVo page = getPage(zxQueryFkExt);
        int records = ywShenQingZxService.countByExt(zxQueryFkExt);
        page.setRecords(records);
        if (records > 0) 
        {
        	zxQueryFkExt.setOrderSql(" t.created desc ");
            List<QueryFkVo> dhywDyVos = ywShenQingZxService.getList(zxQueryFkExt,paramsExt);
            
            if(paramsExt.getExamineStatus().equals("M_zxcxfk"))
            {
            	for(int i=0;i<dhywDyVos.size();i++)
                {
                	QueryFkVo fk = dhywDyVos.get(i);
                	fk.setReasonBack(publicService.getDictionaryName(fk.getReasonBack(),DataDicType.CREDIT_RETURNED_REASON.getCode()));
                 	fk.setBankCode(publicService.getDictionaryName(fk.getBankCode(), DataDicType.LOAN_BANK.getCode()));
                	
                	//身份证号码
                	String cusNo = fk.getCusNo();
                	String sqlXmls = "select t.id,date_format(t.start_date,'%Y-%m-%d %H:%i:%s')start_date from zx_credit_query t left join zx_query_credit_apply_sub p on p.id = t.query_credit_apply_sub_id where t.end_date is not null and t.credit_query_status = 40 and t.dp_status = 1 and p.cus_no = '"+cusNo+"' order by t.created desc limit 1";
                	List<Map<String, String>> resutMpas = publicDao.queryWhereSql(sqlXmls);
                	
                	//如果当前的这条数据信息时间小于  征信保存的结束时间  则标颜色
                	if(null != resutMpas && 0 != resutMpas.size())
                	{
                		for(int j=0;j<resutMpas.size();j++)
                		{
                			//当前查询列表时间
                    		long crdateTime = fk.getCrdateTime();
                    		
                    		//当前的Map
                    		Map<String, String> map = resutMpas.get(j);
                    		
                    		//符合身份证表的时间
                    		String start_date = map.get("start_date").toString();
                    		long time = ZhppDateUtil.dateConvertTimeStamp(start_date, ZhppDateUtil.LONG_DATE_FORMAT) + 86399;
                    		
                    		long d_time = crdateTime - time;
                			
                			if(d_time < (86400 * 30))
                			{
                				fk.setTimeFlag(1);
                				break;
                			}
                		}
                	}
                }
            }
            else
            {
            	 for(int i=0;i<dhywDyVos.size();i++)
                 {
                 	QueryFkVo fk = dhywDyVos.get(i);
                 	fk.setReasonBack(publicService.getDictionaryName(fk.getReasonBack(),DataDicType.CREDIT_RETURNED_REASON.getCode()));
                 	fk.setBankCode(publicService.getDictionaryName(fk.getBankCode(), DataDicType.LOAN_BANK.getCode()));
                 }
            }
            page.setRows(dhywDyVos);
        } 
        else 
        {
            page.setRows(CollectionInitUtil.emptyList());
        }
        maps.put("result", page);
        
        //银行的值
        String examinStatus = paramsExt.getExamineStatus();
        if(null != examinStatus && !examinStatus.equals("M_zxfk"))
        {
        	 Map<String, String> loan_bank = iCachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.LOAN_BANK,"请选择...");
             maps.put("loan_bank", loan_bank);
        }
        return maps;
	}
	
	
	/**
	*  新增征信查询情况表
	*  @author  zhangpp
	*  @Title:  getZxDataResultList  
	*    
	*  @param  @param zxDataResult
	*  @param  @return        设定文件  
	*  @return  ApiResponse        返回类型  
	*  @version  V1.0
	*  @throws
	 */
	@RequestMapping(value = "getZxDataResultList", method = RequestMethod.POST)
    public ApiResponse getZxDataResultList(ZxDataResult zxDataResult)throws Exception
	{
		AbstractSysUser currentUser = getCurrentUser();
		String userId = currentUser.getId();
		String sqlXmls = " select t.code_unit from base_account_busi_unit t where 1 = 1 and t.dp_status = 1 and t.user_id = '"+userId+"' ";
		List<Map<String, String>> mapList = publicService.queryWhereSql(sqlXmls);
		if(null == mapList || 0 == mapList.size())
		{
			return ApiResponse.success(true);
		}
		
		String whereSql = "";
		if(mapList.size() > 0)
		{
			whereSql += " and ( ";
			
			Map<String, String> m = mapList.get(0);
			String code_unit = m.get("code_unit").toString();
			whereSql += " saler.salersman_code like CONCAT('"+code_unit+"','%') ";
			
			for(int i=1;i<mapList.size();i++)
			{
				m = mapList.get(i);
				code_unit = m.get("code_unit").toString();
				whereSql += " or saler.salersman_code like CONCAT('"+code_unit+"','%') ";
			}
			whereSql += " ) ";
		}
		
		//征信查询情况列表 只显示 60天内提交的征信查询信息
		whereSql += " and sub.created > (unix_timestamp()-3600*24*60) ";
		
		//录入时间查询
		if(null != zxDataResult)
		{
			if(StringUtils.isNotBlank(zxDataResult.getSubmitTimeStart()) && StringUtils.isNotBlank(zxDataResult.getSubmitTimeEnd()))
			{
				whereSql += " and t.operator_date >= '"+zxDataResult.getSubmitTimeStart()+"' and t.operator_date <= '"+zxDataResult.getSubmitTimeEnd()+"' ";
			}
			else if(StringUtils.isNotBlank(zxDataResult.getSubmitTimeStart()))
			{
				whereSql += " and t.operator_date >= '"+zxDataResult.getSubmitTimeStart()+"' ";
			}
			else if(StringUtils.isNotBlank(zxDataResult.getSubmitTimeEnd()))
			{
				whereSql += " and t.operator_date <= '"+zxDataResult.getSubmitTimeEnd()+"' ";
			}
		}
		
		//申请时间查询
		if(null != zxDataResult)
		{
			if(StringUtils.isNotBlank(zxDataResult.getShenqingSubmitTimeStart()) && StringUtils.isNotBlank(zxDataResult.getShenqingSubmitTimeEnd()))
			{
				int begDate = ZhppDateUtil.dateConvertTimeStamp(zxDataResult.getShenqingSubmitTimeStart(), "yyyy-MM-dd");
				int endDate = ZhppDateUtil.dateConvertTimeStamp(zxDataResult.getShenqingSubmitTimeEnd(), "yyyy-MM-dd");
				
				whereSql += " and t.created >= "+begDate + " and t.created < "+(endDate + 86400);
			}
			else if(StringUtils.isNotBlank(zxDataResult.getShenqingSubmitTimeStart()))
			{
				int begDate = ZhppDateUtil.dateConvertTimeStamp(zxDataResult.getShenqingSubmitTimeStart(), "yyyy-MM-dd");
				whereSql += " and t.created >= "+begDate;
			}
			else if(StringUtils.isNotBlank(zxDataResult.getShenqingSubmitTimeEnd()))
			{
				int endDate = ZhppDateUtil.dateConvertTimeStamp(zxDataResult.getShenqingSubmitTimeEnd(), "yyyy-MM-dd");
				whereSql += " and t.created <= "+endDate;
			}
		}
		
		zxDataResult.setWhereSql(whereSql);
		zxDataResult.notDeleted();
        PageVo page = getPage(zxDataResult);
        int records = ywShenQingZxService.countZxDataResult(zxDataResult);
        page.setRecords(records);
        if (records > 0) {
            List<ZxDataResult> dpBaseDataDictionaries = ywShenQingZxService.getZxDataResultList(zxDataResult);
            for(int i=0;i<dpBaseDataDictionaries.size();i++)
            {
            	ZxDataResult dataResult = dpBaseDataDictionaries.get(i);
            	dataResult.setBankCode(publicService.getDictionaryName(dataResult.getBankCode(), DataDicType.LOAN_BANK.getCode()));
            }
            page.setRows(dpBaseDataDictionaries);
        } else {
            page.setRows(CollectionInitUtil.emptyList());
        }
        return ApiResponse.success(page);
    }
}
